// pages/homeData/homeData.js
const WxParse =require ('../../wxParse/wxParse.js');
const util = require( '../../utils/util.js');
const app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrls: [
      {
        imgUrls:'../images/house.png',
      },
      {
        imgUrls: '../images/house.png',
      }
    ],
    isShow: false,
    hostUrl: app.globalData.hostUrl,
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 3000,
    duration: 800,
    ellipsis:true,
    huxingLogo: '../images/homeMain.png',
    jibenImg: '../images/jibenxinxi.png',
    cityLogo: '../images/city_logo.png',
    city: '../images/homeImg.png',
    hv: false,

  },
  ellipsis: function (e) {
    var value = !this.data.ellipsis;
    this.setData({
      ellipsis: value
    }) 
  },

  // 点击户型出现轮播
  imgSwiper:function(){
    this.setData({
      isShow: true
    })
  },
  alertColor:function(){
    this.setData({
      isShow: false
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.dichan_info(options.id);
  },
  //地产详情详情
  dichan_info: function (id) {
    var that = this;
    wx.request({
      url: app.globalData.apiUrl + 'Index/dichan_info',
      data: {
        // opt: 'getBanner',
        id: id
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res)
        if (res.data != null) {
          WxParse.wxParse('Content', 'html', res.data["info"].Content, that, 5),
          WxParse.wxParse('Description', 'html', res.data["info"].Description, that, 5),

            that.setData({
              info: res.data,
              markers: [{
                latitude: res.data.info.location_lat,
                longitude: res.data.info.location_lng,
              }],
            })

        }
      }
    })
  },
  //收藏
  shoucang: function (e) {
    var that = this;
    var userId = wx.getStorageSync('userId');
    // console.log(userId);
    // return ;
    if (wx.getStorageSync('userId') !== "") {
      wx.request({
        url: app.globalData.apiUrl + 'Index/collect',
        data: {
          // opt: 'getBanner',
          userId: userId,
          id: e.currentTarget.dataset.id,
          type: 'house',
        },
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          console.log(res)

          if (res.data != null) {
            wx.showToast({
              title: res.data.message,
              icon: 'none'
            })
            that.setData({
              hv: true
            })
          }
        }
      })
    } else {

      wx.showModal({
        title: '请先登录',
        content: 'icon',
      })
    }

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  //onShareAppMessage: function () {

  //},
  index: function () {
    wx.reLaunch({
      url: '../index/index'
    })
  },
  dichan: function () {
    wx.navigateTo({
      url: '../dichan/dichan'
    });
  },
  news: function () {
    wx.navigateTo({
      url: '../news/news'
    });
  },
})